/**
 * Copyright &copy; 2012-2016 <a href="https://istep.lczyfz.com">Istep</a> All rights reserved.
 */
package com.lczyfz.istep.modules.scene.service;

import com.lczyfz.istep.common.persistence.Page;
import com.lczyfz.istep.common.service.CrudService;
import com.lczyfz.istep.modules.scene.dao.SceneSecurityGroupRuleDao;
import com.lczyfz.istep.modules.scene.entity.SceneEnvironment;
import com.lczyfz.istep.modules.scene.entity.SceneSecurityGroup;
import com.lczyfz.istep.modules.scene.entity.SceneSecurityGroupRule;
import com.lczyfz.istep.modules.sys.entity.User;
import com.lczyfz.istep.modules.sys.utils.UserUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * 安全组规则Service
 * @author dh
 * @version 2017-03-28
 */
@Service
@Transactional(readOnly = true)
public class SceneSecurityGroupRuleService extends CrudService<SceneSecurityGroupRuleDao, SceneSecurityGroupRule> {

	public SceneSecurityGroupRule get(String id) {
		return super.get(id);
	}
	
	public List<SceneSecurityGroupRule> findList(SceneSecurityGroupRule sceneSecurityGroupRule) {
		return super.findList(sceneSecurityGroupRule);
	}
	
	public Page<SceneSecurityGroupRule> findPage(Page<SceneSecurityGroupRule> page, SceneSecurityGroupRule sceneSecurityGroupRule) {
		return super.findPage(page, sceneSecurityGroupRule);
	}
	
	@Transactional(readOnly = false)
	public void save(SceneSecurityGroupRule sceneSecurityGroupRule) {
		super.save(sceneSecurityGroupRule);
	}
	
	@Transactional(readOnly = false)
	public void delete(SceneSecurityGroupRule sceneSecurityGroupRule) {
		super.delete(sceneSecurityGroupRule);
	}
	@Transactional(readOnly = false)
	public void insert(SceneSecurityGroupRule sceneSecurityGroupRule) {
		dao.insert(sceneSecurityGroupRule);
	}
	/**
	 * 插入之前执行方法，需要手动调用
	 */
	public void preInsert(SceneSecurityGroupRule sceneSecurityGroupRule) {

		User user = UserUtils.getUser();
		if (StringUtils.isNotBlank(user.getId())) {
			sceneSecurityGroupRule.setUpdateBy(user);
			sceneSecurityGroupRule.setCreateBy(user);
		}
		Date date=new Date();
		sceneSecurityGroupRule.setUpdateDate(date);
		sceneSecurityGroupRule.setCreateDate(date);
	}

	public List<SceneSecurityGroupRule> findSGRListByEnvironmentId(SceneEnvironment sceneEnvironment)
	{
		return  dao.findSGRListByEnvironmentId(sceneEnvironment);
	}
	public List<SceneSecurityGroupRule> findSGRListBySecurityGroupId(SceneSecurityGroup sceneSecurityGroup)
	{
		return  dao.findSGRListBySecurityGroupId(sceneSecurityGroup);
	}


}